﻿using Common.Logging;
using MyData.DB;
using MyWeb.App_Start;
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Mapping;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace MyWeb
{
    public class MvcApplication : System.Web.HttpApplication
    {
        public System.Threading.Thread schedulerThread = null;
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(RouteConfig.RegisterApi);
           
            AutofacExt.InitAutofac();
            using (var webDBContext = new MyDBContext())
            {
                var objectContext = ((IObjectContextAdapter)webDBContext).ObjectContext;
                var mappingCollection = (StorageMappingItemCollection)objectContext.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
                mappingCollection.GenerateViews(new List<EdmSchemaError>());
            }
            Configuration.Configure();
            AreaRegistration.RegisterAllAreas();
            //SchedulerConfiguration config = new SchedulerConfiguration(1000 * 60*3);
            //config.Jobs.Add(new SampleJob());
            //Scheduler scheduler = new Scheduler(config);
            //System.Threading.ThreadStart myThreadStart = new System.Threading.ThreadStart(scheduler.Start);
            //System.Threading.Thread schedulerThread = new System.Threading.Thread(myThreadStart);
            //schedulerThread.Start();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
        }
    }
}
